home *** CD-ROM | disk | FTP | other *** search
- Path: engnews1.Eng.Sun.COM!taumet!clamage
- From: eddy@siemensrolm.com (eddy Gorsuch)
- Newsgroups: comp.std.c++
- Subject: Explicit constructor call vs Temporaries
- Date: 25 Jan 1996 16:12:06 GMT
- Organization: Siemens Rolm Communications Inc.
- Approved: clamage@eng.sun.com (comp.std.c++)
- Message-ID: <4e6plv$idn@eclipse.eng.sc.rolm.com>
- NNTP-Posting-Host: taumet.eng.sun.com
- Content-Type: text
- Content-Length: 929
- X-Lines: 30
- Originator: clamage@taumet
-
- Is an explicit call to an object constructor (an unamed object) const or
- not? I have code like the following where I don't care about the parameter
- to X::f(), so I just created an unamed T(). I thought I had tried to compile
- this code and got errors about trying to pass a const object to a non const
- reference parameter. Thinking that the unamed T() counts as a temporary (and
- therefor const) object, I believed that the compiler was right. Now somebody
- tells me that the following code is legal. Is it?
-
- class T {
- T();
- ~T();
- }
-
- class X {
- X();
- ~X();
- f(T& t);
- }
-
- int main() {
- X x;
- x.f(T()); // Compiler complained on this line
- }
-
- eddy
- --
- ed.dy \'ed-e-\ n [ME (Sc dial.) ydy, prob. fr. ON itha; akin to OHG ith-
- again], L et and 1a: a current of water or air running contrary to the main
- current; esp)X : a small whirlpool 1b: a substance moving similarly 2: a
- contrary or circular current - eddy vb
-
- [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
- Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
- is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
-
-